package com.ad.pet.app.serach;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.CommList;
import com.ad.pet.models.remote.KeyWord;
import com.ad.pet.models.remote.mall.SearchEndGood;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by SEELE on 2018/3/28.
 */

public class SerachHistoryPresenter  extends AbsBasePresenter implements SerachHistoryContract.Presenter{

    private ApiService mApiService;
    private SerachHistoryContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public SerachHistoryPresenter(ApiService apiService,
                         Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }

    @Override
    public void onCreate(SerachHistoryContract.View view) {
        this.mView = view;
    }

    @Override
    public void onDestroy() {
        if (mRxDisposable!=null)
        mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }





    @Override
    public void getKeyword() {
        mRxDisposable.add(mApiService.getHotKeyword()
                .subscribe(new AppSubscriber<List<KeyWord>>(mView) {
                    @Override
                    public void next(List<KeyWord> list) {
                        mView.getKeywordSuccess(list);
                    }
                }));
    }

    @Override
    public void getSearchEnd(String keyword, String page, String limit, String sort, String sort_order, String start_price, String end_price, String category_id,String is_home_cate) {
        mRxDisposable.add(mApiService.getSearchEnd( keyword,  page,  limit,  sort,  sort_order,  start_price,  end_price,  category_id,is_home_cate)
                .subscribe(new AppSubscriber<SearchEndGood>(mView) {
                    @Override
                    public void next(SearchEndGood list) {
                        mView.getSearchEndSuccess(list);
                    }
                }));
    }

    @Override
    public void getTypeWord() {
        mRxDisposable.add(mApiService.main_search_words()
                .subscribe(new AppSubscriber<CommList<List<KeyWord>>>(mView) {
                    @Override
                    public void next(CommList<List<KeyWord>> list) {
                        mView.getTypeWordSucceses(list.getList());
                    }
                }));
    }

    @Override
    public void getCateGoryWord() {
        mRxDisposable.add(mApiService.getcategorylist()
                .subscribe(new AppSubscriber<CommList<List<KeyWord>>>(mView) {
                    @Override
                    public void next(CommList<List<KeyWord>> list) {
                        mView.getTypeWordSucceses(list.getList());
                    }
                }));
    }
}
